package com.rui.common.util;

import java.io.Serializable;
import java.util.Random;
import java.util.UUID;

/**
 * id生成util
 *
 * @author xr
 * @email xr@qq.com
 * @date 2020-01-01 00:00:00
 */
public class GenUtil implements Serializable {
    private static final String NUMBER_CHAR = "0123456789";

    /**
     * 雪花算法生成全局唯一id
     *
     * @return
     */
    public static Long genId() {
        return IdWorker.genId();
    }

    /**
     * UUID
     *
     * @return 32位UUID
     */
    public static String uuid() {
        return UUID.randomUUID().toString().replace("-", "");
    }

    /**
     * 区间随机
     *
     * @param max 最大值
     * @param min 最小值
     * @return
     */
    public static int random(int max, int min) {
        return (int) (Math.random() * (max - min) + min);
    }

    /**
     * 随机数
     *
     * @param len 长度
     * @return
     */
    public static String random(int len) {
        StringBuilder stringBuilder = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < len; i++) {
            stringBuilder.append(NUMBER_CHAR.charAt(random.nextInt(NUMBER_CHAR.length())));
        }
        return stringBuilder.toString();
    }

}
